package com.summer.content.api;

import com.summer.content.service.CoursePublishService;
import com.summer.dto.CoursePreviewDto;
import com.summer.pojo.CoursePublish;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Api(value = "课程预览发布接口", tags = "课程预览发布接口")
@Slf4j
@Controller
public class CoursePublishController {

    @Autowired
    private CoursePublishService coursePublishService;

    @ApiOperation("课程预览api")
    @GetMapping("coursepreview/{courseId}")
    public ModelAndView coursePreview(@PathVariable Long courseId, ModelAndView modelAndView){
        log.info("请求课程预览api， courseId = {}", courseId);

        CoursePreviewDto coursePreview = coursePublishService.getCoursePreview(courseId);
        modelAndView.setViewName("course_template");  // 后缀名在yml中已配置
        modelAndView.addObject("model", coursePreview);

        return modelAndView;
    }

    @ApiOperation("课程提交审核")
    @ResponseBody
    @PostMapping("/courseaudit/commit/{courseId}")
    public void commitAudit(@PathVariable("courseId") Long courseId){
        Long companyId = 1232141425L;
        coursePublishService.commitAudit(companyId, courseId);
    }

    @ApiOperation("课程发布")
    @PostMapping("coursepublish/{courseId}")
    public void coursePublish(@PathVariable("courseId") Long courseId){
        Long companyId = 1232141425L;
        coursePublishService.coursePublish(companyId, courseId);
    }

    @ApiOperation("课程发布")
    @GetMapping("coursepublish/getById/{courseId}")
    @ResponseBody
    public CoursePublish getById(@PathVariable long courseId){
        return coursePublishService.getById(courseId);
    }


}
